﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;

namespace POSReportSingleTier
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConn = new SqlConnection(@"data source=BAINISYS-PC\SQL2008R2;initial catalog=BPM_Report;user id=sa;password=Password123");
            SqlCommand sqlCmd = new SqlCommand("CloseWorkSummaryReport", sqlConn);
            //SqlCommand sqlCmd = new SqlCommand("teststore", sqlConn);
            sqlCmd.CommandType = CommandType.StoredProcedure;

            int tempTime =  Convert.ToInt32(txtTime.Text);
            
            //SqlParameter Timekey = sqlCmd.Parameters.Add("@TimeKey", SqlDbType.Int, tempTime);
            sqlCmd.Parameters.AddWithValue("TimeKey", tempTime);

            //Timekey.Direction = ParameterDirection.ReturnValue;
            //SqlParameter IdIn = sqlCmd.Parameters.Add
            //  ("@au_idIN", SqlDbType.VarChar, 11);
            //IdIn.Direction = ParameterDirection.Input;
            //SqlParameter NumTitles = sqlCmd.Parameters.Add
            //   ("@numtitlesout", SqlDbType.VarChar, 11);
            //NumTitles.Direction = ParameterDirection.Output;

            sqlConn.Open();
            SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
            DataSet ds = new DataSet();
            //sda.Fill(ds,"DataSet1");
            sda.Fill(ds, "CloseWorkSummaryDT");
            sqlConn.Close();

            // Retrieving total stored tables from a common DataSet.              
            //DataTable dt1 = ds.Tables[0];
            //DataTable dt2 = ds.Tables[1];
            //DataTable dt3 = ds.Tables[2];
            //DataTable dt4 = ds.Tables[3];

            // To display all rows of a table, we use foreach loop for each DataTable.
            //foreach (DataRow dr in dt1.Rows)
            //{
            //    Console.WriteLine("Student Name: " + dr[sName]);
            //}

            //======================================Display===========================================//
            //CloseWorkReport objRpt = new CloseWorkReport();
            CloseWorkSummaryReport objRpt = new CloseWorkSummaryReport();
            objRpt.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
            objRpt.SetDataSource(ds);
            // Binding the crystalReportViewer with our report object.
            
            crystalReportViewer1.ReportSource = objRpt;
 
  
            //======================================Display===========================================//
        }
    }
}
